package com.rj.bd;

/**
 * @desc 求一个3*3矩阵对角线元素之和
 * @author lipf
 * @time 2021-09-07
 */
public class Test03 {

	public static void main(String[] args) {
		int sum = 0;
		int[][] a = { { 1, 2, 3 }, 
					  { 4, 5, 6 }, 
				      { 7, 8, 9 }} ;
			
		for (int i = 0; i < 3; i++) {
			int b = a[i][i];
			sum += b;
		}
		int k = 2;
		for (int i = 0; i < 3; i++) {
			int c = a[i][k];
			k -= 1;
			sum += c;

		}
		System.out.println("对角线之和为："+sum);
	}

}
